//
//  WKDownLoadViewController.m
//  WeKeTang
//
//  Created by ichina on 2017/8/24.
//  Copyright © 2017年 Dezhi Tiancheng Education Technology (Beijing) Co. Ltd. All rights reserved.
//

#import "WKDownLoadViewController.h"
#import "WKTableView.h"
#import "WKEditorView.h"
#import "WKNetworkTools.h"
#import "GCDWebServer.h"
#import "WKPlayerViewController.h"
#import "WKNomalTableViewCell.h"
#import "WKDownloadingCell.h"
#import "WKDownLoadManger.h"
#import "WKFMDBTools.h"
#import "WKAlerView.h"

@interface WKDownLoadViewController ()<UITableViewDelegate,UITableViewDataSource,WKEditorViewDelegate,WKDownloadingCellDelegate>

@property (nonatomic, strong) UIButton *btnRight;
@property (weak, nonatomic) IBOutlet UIView *lineView;
@property (weak, nonatomic) IBOutlet UIButton *btnCompleted;
@property (weak, nonatomic) IBOutlet UIButton *btnUnCompleted;
@property (strong, nonatomic) UITableView*mainTableView;
@property (nonatomic, strong) UIImageView *maskImgView;
@property (nonatomic, strong) WKEditorView *editorView;
@property (nonatomic, assign) NSInteger recode;
@property (nonatomic, strong) NSArray *dataList;
@property (nonatomic, strong) GCDWebServer *webServer;
@property(nonatomic, strong) NSMutableArray *deleteArr;//标记数据的数组
@property (nonatomic, strong) NSArray  *tempArr;
@property (nonatomic, strong) YYLabel *footerLabel;
@property (nonatomic, assign) BOOL isFinish;
@property (nonatomic, assign) BOOL isDowloading;
@property (nonatomic, strong) WKAlerView *alertView;
@property (nonatomic, strong) NSTimer *timer;
@property (nonatomic, strong) UIView *leftView;
@property (nonatomic, strong) UIView *rightView;
@property (nonatomic, strong) UIView *bottomView;
@property (nonatomic, strong) UIView *leftUnView;
@property (nonatomic, strong) UIView *rightUnView;
@property (nonatomic, strong) UIView *bottomUnView;

@end

@implementation WKDownLoadViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navItem.title = @"我的下载";
    self.recode = 0;
    
    self.deleteArr = [NSMutableArray array];
    
    [self loadData];
    
    [self setupUI];
    
}
- (void)loadData{
    
    //拿到下载完成的数据
    self.dataList = [[WKFMDBTools defaultFMDBToos]QueryDataWithTableName:kDBTableName Key:kStatusFinish].mutableCopy;

    NSLog(@"已下载完的数据：%@",self.dataList);
}
- (void)setupUI{
    
    self.navgationBar.barTintColor=[UIColor whiteColor];
    self.statusbar.backgroundColor = RGBColor(40, 188, 203);
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
    [self middleTitleColor:[UIColor blackColor]];
    self.navItem.leftBarButtonItem = nil;
    [self setLeftButtonWithImage:@"icon_return" highlightedImage:@"icon_return" target:self action:@selector(backAction)];
    [self.navgationBar addSubview:self.btnRight];
    
    self.mainTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 105, kDeviceScreenWidth, kDeviceScreenHeight-95) style:UITableViewStylePlain];
    self.mainTableView.delegate = self;
    self.mainTableView.dataSource = self;
    [self.view addSubview:self.mainTableView];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(backfroundAction:) name:UIApplicationDidEnterBackgroundNotification object:nil];
    self.mainTableView.editing = NO;
    
    UIView *footView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kDeviceScreenWidth, 80)];
    self.footerLabel = [[YYLabel alloc]initWithFrame:CGRectMake(0, 0, kDeviceScreenWidth, 21)];
    self.footerLabel.center = footView.center;
    self.footerLabel.text = @"已加载全部内容";
    self.footerLabel.textColor = [UIColor colorWithHexString:@"#666666"];
    self.footerLabel.textAlignment = NSTextAlignmentCenter;
    self.footerLabel.font = [UIFont systemFontOfSize:13];
    [footView addSubview:self.footerLabel];
    self.mainTableView.tableFooterView = footView;

    self.editorView = [[WKEditorView alloc]initWithFrame:CGRectMake(0, kDeviceScreenHeight, kDeviceScreenWidth, 70)];
    self.editorView.backgroundColor = RGBColor(245, 245, 245);
    self.editorView.delegate = self;
    [self.view addSubview:self.editorView];
    
    self.maskImgView = [[UIImageView alloc]initWithFrame:CGRectMake((kDeviceScreenWidth - 150)*0.5, (kDeviceScreenHeight - 120)*0.5, 150, 120)];
    self.maskImgView.image = [UIImage imageNamed:@"icon_undownloadcourse"];
    self.maskImgView.hidden = YES;
    [self.view addSubview:self.maskImgView];
    //默认选中已下载完成
    [self btnCompletedAction:nil];
    
}
-(void)backAction{
    
    [super backAction];
    if (self.block) {
        self.block();
    }
}
#pragma mark - 监听程序回到后台
- (void)backfroundAction:(NSNotification*)nofi{
    [self.webServer removeObserverBlocks];
}
#pragma mark - 已完成
- (IBAction)btnCompletedAction:(UIButton *)sender {
    self.mainTableView.editing = NO;
    [self dismissEditorView];
    [self.editorView.btnDelete setTitle:@"删除" forState:UIControlStateNormal];
    [self.deleteArr removeAllObjects];
    [self.alertView removeFromSuperview];
    [self.btnRight setImage:IMG(@"icon_edtiorImg") forState:UIControlStateNormal];
    [self.btnRight setTitle:nil forState:UIControlStateNormal];
    [self.timer invalidate];
    self.timer = nil;
    [self.mainTableView registerClass:[WKNomalTableViewCell class] forCellReuseIdentifier:@"nomalCell"];
    _isFinish = YES;
    _isDowloading = NO;
    sender.backgroundColor = [UIColor whiteColor];

    self.btnUnCompleted.backgroundColor = [UIColor colorWithHexString:@"#f4f4f4"];
    [self.leftView removeFromSuperview];
    [self.bottomView removeFromSuperview];
    [self.rightView removeFromSuperview];
    [self.leftUnView removeFromSuperview];
    [self.bottomUnView removeFromSuperview];
    [self.rightUnView removeFromSuperview];
    
    self.leftView = [[UIView alloc]init];
    self.leftView.backgroundColor = [UIColor colorWithHexString:@"#e0e0e0"];
    self.leftView.frame = CGRectMake(self.btnUnCompleted.left, self.btnUnCompleted.top, 0.5, self.btnUnCompleted.height);
    [self.view addSubview:self.leftView];
    self.bottomView = [[UIView alloc]init];
    self.bottomView.backgroundColor = [UIColor colorWithHexString:@"#e0e0e0"];
    self.bottomView.frame = CGRectMake(self.btnUnCompleted.left, self.btnUnCompleted.bottom, self.btnUnCompleted.width, 0.5);
    [self.view addSubview:self.bottomView];
    self.rightView = [[UIView alloc]init];
    self.rightView.backgroundColor = [UIColor colorWithHexString:@"#e0e0e0"];
    self.rightView.frame = CGRectMake(self.btnUnCompleted.right, self.btnUnCompleted.top, 0.5, self.btnUnCompleted.height);
    [self.view addSubview:self.rightView];
    self.dataList = [[WKFMDBTools defaultFMDBToos]QueryDataWithTableName:kDBTableName Key:kStatusFinish].mutableCopy;
    self.dataList = [[self.dataList reverseObjectEnumerator] allObjects];
    NSLog(@"-------------------%ld",self.dataList.count);
    [self.mainTableView reloadData];
    
    if (self.dataList.count == 0) {
        self.footerLabel.hidden = YES;
        self.maskImgView.hidden = NO;
        
    }else{
        self.maskImgView.hidden = YES;
        self.footerLabel.hidden = NO;
    }
}
#pragma mark - 未完成
- (IBAction)btnUnCompleted:(UIButton *)sender {
    self.mainTableView.editing = NO;
    [self dismissEditorView];
    [self.editorView.btnDelete setTitle:@"删除" forState:UIControlStateNormal];
    [self.deleteArr removeAllObjects];
    [self.alertView removeFromSuperview];
    [self.btnRight setImage:IMG(@"icon_edtiorImg") forState:UIControlStateNormal];
    [self.btnRight setTitle:nil forState:UIControlStateNormal];
    [self.mainTableView registerClass:[WKDownloadingCell class] forCellReuseIdentifier:@"downLoadCell"];
    _isFinish = NO;
    _isDowloading = YES;
    sender.backgroundColor = [UIColor whiteColor];
    [self.leftUnView removeFromSuperview];
    [self.bottomUnView removeFromSuperview];
    [self.rightUnView removeFromSuperview];
    [self.leftView removeFromSuperview];
    [self.bottomView removeFromSuperview];
    [self.rightView removeFromSuperview];
    self.leftUnView = [[UIView alloc]init];
    self.leftUnView.backgroundColor = [UIColor colorWithHexString:@"#e0e0e0"];
    self.leftUnView.frame = CGRectMake(self.btnCompleted.left, self.btnCompleted.top, 0.5, self.btnCompleted.height);
    [self.view addSubview:self.leftUnView];
    self.bottomUnView = [[UIView alloc]init];
    self.bottomUnView.backgroundColor = [UIColor colorWithHexString:@"#e0e0e0"];
    self.bottomUnView.frame = CGRectMake(self.btnCompleted.left, self.btnCompleted.bottom, self.btnCompleted.width, 0.5);
    [self.view addSubview:self.bottomUnView];
    self.rightUnView = [[UIView alloc]init];
    self.rightUnView.backgroundColor = [UIColor colorWithHexString:@"#e0e0e0"];
    self.rightUnView.frame = CGRectMake(self.btnCompleted.right, self.btnCompleted.top, 0.5, self.btnCompleted.height);
    [self.view addSubview:self.rightUnView];
    self.btnCompleted.backgroundColor = [UIColor colorWithHexString:@"#f4f4f4"];

    //获取数据
    self.dataList = [[WKFMDBTools defaultFMDBToos]QueryDataWithTableName:kDBTableName Key:kStatusDowning].mutableCopy;
    
    [self.mainTableView reloadData];
    
    NSLog(@"未下载完的数据：%@",self.dataList);
    
    if (self.dataList.count == 0) {
        self.maskImgView.hidden = NO;
        self.footerLabel.hidden = YES;
    }else{
        self.maskImgView.hidden = YES;
        self.footerLabel.hidden = NO;
    }
    self.timer = [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(refreshData) userInfo:nil repeats:YES];
    [[NSRunLoop currentRunLoop]addTimer:self.timer forMode:NSRunLoopCommonModes];
}
#pragma mark - 定时器刷新数据
- (void)refreshData{
    //获取数据
    self.dataList = [[WKFMDBTools defaultFMDBToos]QueryDataWithTableName:kDBTableName Key:kStatusDowning].mutableCopy;
    
    [self.mainTableView reloadData];
}
#pragma mark - 编辑
- (void)rightBtnAction:(UIButton*)sender{
    if (_isDowloading) {
        [self.timer invalidate];
        self.timer = nil;
    }
    self.mainTableView.allowsMultipleSelectionDuringEditing = YES;
    self.mainTableView.editing = !self.mainTableView.editing;
    
    if (self.mainTableView.editing){
        [self.btnRight setTitle:@"取消" forState:UIControlStateNormal];
        [self.btnRight setTitleColor:RGBColor(40, 188, 203) forState:UIControlStateNormal];
        [self.btnRight setImage:nil forState:UIControlStateNormal];
        NSLog(@"----------%ld",self.deleteArr.count);
        if (self.deleteArr.count != 0) {
        [self.editorView.btnDelete setTitle:[NSString stringWithFormat:@"删除(%ld)",self.deleteArr.count] forState:UIControlStateNormal];
        }else{
             [self.editorView.btnDelete setTitle:@"删除" forState:UIControlStateNormal];
        }
        [self showEditorView];
        
    }else{
        [_btnRight setImage:IMG(@"icon_edtiorImg") forState:UIControlStateNormal];
        [self.btnRight setTitle:nil forState:UIControlStateNormal];
        self.editorView.btnSelectAll.selected = NO;
        [self.deleteArr removeObjectsInArray:self.dataList];
        self.timer = [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(refreshData) userInfo:nil repeats:YES];
        [[NSRunLoop currentRunLoop]addTimer:self.timer forMode:NSRunLoopCommonModes];
        NSLog(@"----------%ld",self.deleteArr.count);
        [self dismissEditorView];
    }
}
#pragma mark - 全选
- (void)WKEditorView:(WKEditorView *)wkEditorView btnSelectAllAction:(UIButton *)sender{
    
    sender.selected =! sender.selected;
    if (sender.selected) {
       [sender setTitle:@"取消全选" forState:UIControlStateSelected];
         [self.deleteArr removeObjectsInArray:self.dataList];
        for (int i = 0; i < self.dataList.count; i ++) {
            NSIndexPath *indexPath = [NSIndexPath indexPathForItem:i inSection:0];
            [self.mainTableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionTop];
            
        }
        NSLog(@"全选=====：%ld",self.deleteArr.count);
        [self.deleteArr removeAllObjects];
        [self.deleteArr addObjectsFromArray:self.dataList];
        NSLog(@"全选=====：%ld",self.dataList.count);
        NSLog(@"全选=====：%ld",self.deleteArr.count);
        if (self.deleteArr.count != 0) {
            [self.editorView.btnDelete setTitle:[NSString stringWithFormat:@"删除(%ld)",self.deleteArr.count] forState:UIControlStateNormal];
        }
        NSLog(@"全选：%ld",self.deleteArr.count);
    }else{
        [sender setTitle:@"全选" forState:UIControlStateNormal];
        [self.deleteArr removeObjectsInArray:self.dataList];
        [self rightBtnAction:nil];
    }
}
#pragma mark -删除
- (void)WKEditorView:(WKEditorView *)wkEditorView btnDeleteAction:(UIButton *)sender{
    if (self.deleteArr.count == 0 && self.dataList.count == 0) {
        [self showCustomAlertMessage:@"请选择条目!"];
        return;
    }else if (self.deleteArr.count == 0){
        [self showCustomAlertMessage:@"请选择要删除的内容!"];
        return;
        
    }
    __weak typeof(self) weakSelf = self;
    //弹框
    self.alertView = [[WKAlerView alloc]initWithFrame:[UIScreen mainScreen].bounds message:@"确定要删除这些数据？" tip:nil title1:@"确定" title2:@"取消"];
    self.alertView.confirmBlock = ^{
        //执行删除操作
        [weakSelf deleteDownloadCourse];
        
        [weakSelf.alertView removeFromSuperview];
    };
    self.alertView.cancelBlock = ^{
        [weakSelf cancelDelegateWatchData];
        [weakSelf.alertView removeFromSuperview];
    };
    self.alertView.deleteBlock = ^{
         [weakSelf cancelDelegateWatchData];
        [weakSelf.alertView removeFromSuperview];
    };
    [[UIApplication sharedApplication].keyWindow addSubview:self.alertView];
    
    [self dismissEditorView];
}
#pragma mark - 删除下载的视频
- (void)deleteDownloadCourse{
    //从新加载数据
    if (_isFinish) {
        for (NSInteger i =0; i<self.deleteArr.count; i++) {
            WKDownLoadModel *model = self.deleteArr[i];
            [[WKFMDBTools defaultFMDBToos]delegateDownLoadVideoWithTableName:kDBTableName section_videoid:model.section_videoid];
        }
        [self.deleteArr removeAllObjects];
        self.dataList = [[WKFMDBTools defaultFMDBToos]QueryDataWithTableName:kDBTableName Key:kStatusFinish].mutableCopy;
        NSLog(@"-------------------%ld",self.dataList.count);
        [self.mainTableView reloadData];
        if (self.dataList.count == 0) {
            self.maskImgView.hidden = NO;
            self.footerLabel.hidden = YES;
        }else{
            self.maskImgView.hidden = YES;
            self.footerLabel.hidden = NO;
        }
    }
    if (_isDowloading) {
        for (NSInteger i =0; i<self.deleteArr.count; i++) {
            WKDownLoadModel *model = self.deleteArr[i];
            [[WKFMDBTools defaultFMDBToos]delegateDownLoadVideoWithTableName:kDBTableName section_videoid:model.section_videoid];
        }
        [self.deleteArr removeAllObjects];
        //获取数据
        self.dataList = [[WKFMDBTools defaultFMDBToos]QueryDataWithTableName:kDBTableName Key:kStatusDowning].mutableCopy;
        [self.mainTableView reloadData];
        if (self.dataList.count == 0) {
            self.maskImgView.hidden = NO;
            self.footerLabel.hidden = YES;
        }else{
            self.maskImgView.hidden = YES;
            self.footerLabel.hidden = NO;
        }
    }
}
- (void)cancelDelegateWatchData{
    
    self.mainTableView.editing = NO;
    [self.btnRight setImage:IMG(@"icon_edtiorImg") forState:UIControlStateNormal];
    [self.btnRight setTitle:nil forState:UIControlStateNormal];
    self.editorView.btnSelectAll.selected = NO;
    [self dismissEditorView];
    [self.editorView.btnDelete setTitle:@"删除" forState:UIControlStateNormal];
    [self.deleteArr removeAllObjects];
    [self.alertView removeFromSuperview];
}
#pragma mark - 数据源方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return self.dataList.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (_isFinish) {
        static NSString *cellID1 = @"nomalCell";
        
        WKNomalTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID1];
        if (!cell) {
            cell = [[WKNomalTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID1];
        }
        cell.selectedBackgroundView = [[UIView alloc]init];
        cell.model = self.dataList[indexPath.row];
        cell.tintColor = [UIColor lightGrayColor];// 改变编辑状态左侧勾选颜色
        
        return  cell;
    }
    static NSString *cellID2 = @"downLoadCell";
    
    WKDownloadingCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID2];
    
    if (!cell) {
        cell = [[WKDownloadingCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID2];
    }
    cell.selectedBackgroundView = [[UIView alloc]init];
    cell.tintColor = [UIColor lightGrayColor];// 改变编辑状态左侧勾选颜色
    cell.delegate = self;
    cell.model = self.dataList[indexPath.row];
    return cell;

    return nil;
}
#pragma mark - 暂停下载
- (void)WKDownloadingCell:(WKDownloadingCell *)wkDownLoadCell withSender:(UIButton *)sender section_videoid:(NSString *)section_videoid dict:(NSDictionary *)dict{
    sender.selected = !sender.selected;
    NSArray *dbDownLoadList = [[WKFMDBTools defaultFMDBToos] QueryDownloadingDataWithTableName:kDBTableName status:kStatusDowning].mutableCopy;
    if (dbDownLoadList.count == 0) {//没有正在下载的视频
        sender.selected = NO;
    }else{//有正在下载的视频
        sender.selected = YES;
    }
    if (sender.selected) {
        //暂停下载
        [sender setImage:[UIImage imageNamed:@"icon_supendtip"] forState:UIControlStateNormal];
        [[NSNotificationCenter defaultCenter]postNotificationName:@"supend" object:nil];
    }else{
        [sender setImage:[UIImage imageNamed:@"icon_downloading"] forState:UIControlStateNormal];
        //继续下载
        [[NSNotificationCenter defaultCenter]postNotificationName:@"continuedown" object:nil userInfo:dict];
    }
}
#pragma mark - tableView代理方法
//是否可以编辑  默认的时YES
-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{
    return YES;
}

//选择编辑的方式,按照选择的方式对表进行处理
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        
    }
    
}
//选择你要对表进行处理的方式  默认是删除方式
-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
    return UITableViewCellEditingStyleDelete | UITableViewCellEditingStyleInsert;
}

//选中时将选中行的在self.dataArray 中的数据添加到删除数组self.deleteArr中
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    __weak typeof(self) weakSelf = self;
    if (_isDowloading) {
        return;
    }
    if (!self.mainTableView.editing) {
        
        WKNomalTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"nomalCell"];
        
        cell.model = self.dataList[indexPath.row];
        
        // 本地服务器生成地址
        NSString *pathText = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
        pathText = [pathText stringByAppendingPathComponent:[NSString stringWithFormat:@"%@video",cell.model.section_name]];
        NSLog(@"服务器拼接的地址:%@",pathText);
        NSString *paths = [NSString stringWithFormat:@"%@/",pathText];
        self.webServer = [[GCDWebServer alloc] init];
        [self.webServer addGETHandlerForBasePath:@"/" directoryPath:paths indexFilename:@"order.m3u8" cacheAge:3600 allowRangeRequests:YES];
        [self.webServer startWithPort:8080 bonjourName:nil];
        dispatch_async(dispatch_get_main_queue(), ^{
            WKPlayerViewController *playerVC = [[WKPlayerViewController alloc]init];
            playerVC.vurl = @"http://localhost:8080/order.m3u8";
            playerVC.placeholderImage = cell.model.section_imgurl;
            playerVC.section_name = cell.model.section_name;
            playerVC.block = ^(NSInteger currentTime, NSInteger totalTime) {
                 [[WKFMDBTools defaultFMDBToos] UpdateDownloadWatchDataWithTabelName:kDBTableName currentWatchCount:[NSString stringWithFormat:@"%ld",currentTime] totalWatchCount:[NSString stringWithFormat:@"%ld",totalTime] section_videoid:cell.model.section_videoid];
            };
            weakSelf.dataList = [[WKFMDBTools defaultFMDBToos]QueryDataWithTableName:kDBTableName Key:kStatusFinish].mutableCopy;
            NSLog(@"-------------------%ld",weakSelf.dataList.count);
            [weakSelf.mainTableView reloadData];
            [self.navigationController pushViewController:playerVC animated:YES];
        });
        
    }else{
        
        //数据处理
        [self.deleteArr addObject:[self.dataList objectAtIndex:indexPath.row]];
        if (self.deleteArr.count != 0) {
            [self.editorView.btnDelete setTitle:[NSString stringWithFormat:@"删除(%ld)",self.deleteArr.count] forState:UIControlStateNormal];
        }else{
            [self.editorView.btnDelete setTitle:[NSString stringWithFormat:@"删除"] forState:UIControlStateNormal];
        }
    }
}
//取消选中时 将存放在self.deleteArr中的数据移除
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath  {
    if (tableView.editing) {
        [self.deleteArr removeObject:[self.dataList objectAtIndex:indexPath.row]];
        if (self.deleteArr.count != 0) {
            [self.editorView.btnDelete setTitle:[NSString stringWithFormat:@"删除(%ld)",self.deleteArr.count] forState:UIControlStateNormal];
        }else{
            [self.editorView.btnDelete setTitle:[NSString stringWithFormat:@"删除"] forState:UIControlStateNormal];
        }
        NSLog(@"单选：%ld",self.deleteArr.count);
    }else{
        
        //[self showCustomAlertMessage:@"点击播放"];
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 120;
}
- (void)showEditorView{
    
    [UIView animateWithDuration:0.2 animations:^{
        self.editorView.frame = CGRectMake(0, kDeviceScreenHeight - 70, kDeviceScreenWidth, 70);
    }];
    
    
}
- (void)dismissEditorView{
    
    [UIView animateWithDuration:0.2 animations:^{
        self.editorView.frame = CGRectMake(0, kDeviceScreenHeight, kDeviceScreenWidth, 70);
    }];
    
}
- (UIButton *)btnRight{
    
    if (_btnRight == nil) {
        _btnRight = [UIButton  buttonWithType:UIButtonTypeCustom];
        _btnRight.frame = CGRectMake(kDeviceScreenWidth - 40, (44-35)*0.5, 35,35);
        [_btnRight setImage:IMG(@"icon_edtiorImg") forState:UIControlStateNormal];
        [_btnRight setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _btnRight.titleLabel.font = [UIFont systemFontOfSize:15];
        [_btnRight addTarget:self action:@selector(rightBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _btnRight;
}
- (void)viewDidLayoutSubviews{
    [super viewDidLayoutSubviews];
    self.leftView.frame = CGRectMake(self.btnUnCompleted.left, self.btnUnCompleted.top, 0.5, self.btnUnCompleted.height);
    self.bottomView.frame = CGRectMake(self.btnUnCompleted.left, self.btnUnCompleted.bottom, self.btnUnCompleted.width, 0.5);
    self.rightView.frame = CGRectMake(self.btnUnCompleted.right, self.btnUnCompleted.top, 0.5, self.btnUnCompleted.height);
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}

@end
